*******************************************	   
************* FIGURE A8 Counterfactual Experiment
*******************************************	   

clear all
clear matrix
set more off
set matsize 11000

* Use data from results: 

use "~/Dropbox/Replication_MVC/Datasets/datasets_analysis/panel_excombatientes.dta", clear 

* Do a stabilizing transformation (inverse hyperbolic sine, IHS) 
* to get better yhat predictions:
g ldiffcaptures = asinh(diffcaptures)
g ldiffcaptures_f = asinh(diffcaptures_f)

eststo clear
set more off

xi: areg ldiffcaptures_f gold_shock mean_gold_shock i.year i.origmun, absorb(wartimenetwork) vce(cluster wartimenetwork)
estadd local ALLFE = "$\checkmark$"
summ diffcaptures_f if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo
	   	   
* Now, here are the model predictions under actual prevailing 
* circumstances (log scale because of the
* IHS transformation):
predict xb_gold_fla

* Then if, counterfactually, we removed the effects of peers---that is,
* we make beta=0.5, theta is also reduced.
* For counterfactual, subtract out the theta*mean_gold_shock component
g xb_gold_beta50_fla = xb_gold_fla - _b[mean_gold_shock]*mean_gold_shock*.5

* Convert the predictions to nominal scale:
g yhat_gold_fla = exp(xb_gold_fla)
g yhat_gold_beta50_fla = exp(xb_gold_beta50_fla)

* Plot predictions against the mean gold shock, along with actual:
sort mean_gold_shock
la var diffcaptures_f "Red-Handed Captures"
la var yhat_gold_fla "Predictions under actual"
la var yhat_gold_beta50_fla "Predictions counterfactual"

twoway (scatter diffcaptures_f mean_gold_shock, mcolor(gray) msize(tiny) jitter(2)) (line yhat_gold_fla mean_gold_shock, lcolor(red)) (line yhat_gold_beta50_fla mean_gold_shock, lcolor(blue)), ytitle("Red-Handed Captures") xtitle("Mean Gold Shock")  xlabel(0(250)1750, grid)  graphregion(color(white)) legend(ring(0) position(10) size(small) col(1))

* The difference between the two lines measures the difference that 
* an intervention rendering beta = 0.5 would have on capture rates.

* Numerically, we have:
sum yhat_gold_fla 
scalar mean_captures_gold2 = r(mean)
sum yhat_gold_beta50_fla
scalar  mean_captures_gold_beta502 = r(mean)
di  1 - (mean_captures_gold_beta502/mean_captures_gold2)
* So about 12% reduction in arrests.
